//
//  PickerDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/7/1.
//

import SwiftUI

struct PickerDemo: View {
    
    @State var selection: String = "1"
    
    let filterOptions: [String] = [
        "Most Recent", "Most Popular", "Most Liked", "Most Share"
    ]
    
    init() {
        UISegmentedControl.appearance().selectedSegmentTintColor = .red
        let attributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: UIColor.white,
//            .backgroundColor: UIColor.green
            .font: UIFont.systemFont(ofSize: 20)
        ]
        UISegmentedControl.appearance().setTitleTextAttributes(attributes, for: .selected)
    }
    
    var body: some View {
        
        Picker(selection: $selection,
               label:
                HStack {
            Text("Filter")
            Text(selection)
        }
            .font(.headline)
            .foregroundColor(.white)
            .padding()
            .padding(.horizontal)
            .background(Color.blue)
            .cornerRadius(10)
            .shadow(color: Color.blue.opacity(0.3), radius: 10, x: 0.0, y: 10)
        , content: {
            ForEach(filterOptions, id: \.self) { option in
                Text(option).tag(option)
            }
        })
        .pickerStyle(SegmentedPickerStyle())
//        .background(.red)
        
        
        Picker(selection: $selection,
               label:
                HStack {
            Text("Filter")
            Text(selection)
        }
            .font(.headline)
            .foregroundColor(.white)
            .padding()
            .padding(.horizontal)
            .background(Color.blue)
            .cornerRadius(10)
            .shadow(color: Color.blue.opacity(0.3), radius: 10, x: 0.0, y: 10)
        , content: {
            ForEach(filterOptions, id: \.self) { option in
                Text(option).tag(option)
            }
        })
        
        Picker(selection: .constant(1)) {
            Text("1").tag("1")
            Text("2").tag("2")
        } label: {
                        Text("Picker")
            //            selection =
        }
        .pickerStyle(MenuPickerStyle())
        
        
        VStack {
            
            HStack {
                Text("Age:")
                Text(selection)
            }
            Picker(selection: $selection) {
                ForEach(18..<100) { index in
                    Text("\(index)").tag("\(index)")
                }
            } label: {
                            Text("selection")
                //            selection =
            }
            .pickerStyle(WheelPickerStyle())
//            .background(.red)
        }

    }
}

#Preview {
    PickerDemo()
}
